package com.ruoyi.biz.service.impl;

import java.util.List;

import com.ruoyi.biz.domain.SensorInfo;
import com.ruoyi.biz.mapper.SensorInfoMapper;
import com.ruoyi.biz.service.ISensorInfoService;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author ruoyi
 * @date 2020-11-30
 */
@Service
public class SensorInfoServiceImpl implements ISensorInfoService
{
    @Resource
    private SensorInfoMapper sensorInfoMapper;

    /**
     * 查询【请填写功能名称】
     *
     * @param sensorId 【请填写功能名称】ID
     * @return 【请填写功能名称】
     */

    @Override
    public SensorInfo selectSensorInfoById(Long sensorId)
    {
        return sensorInfoMapper.selectSensorInfoById(sensorId);
    }

    /**
     * 查询【请填写功能名称】列表
     * 部门及用户权限注解
     * @param sensorInfo 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @DataScope(deptAlias = "d", userAlias = "u")
    @Override
    public List<SensorInfo> selectSensorInfoList(SensorInfo sensorInfo)
    {
        return sensorInfoMapper.selectSensorInfoList(sensorInfo);
    }

    /**
     * 新增【请填写功能名称】
     *
     * @param sensorInfo 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertSensorInfo(SensorInfo sensorInfo)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser user = loginUser.getUser();
        sensorInfo.setDeptId(user.getDeptId());
        sensorInfo.setCreateTime(DateUtils.getNowDate());
        sensorInfo.setCreateBy(user.getUserName());
        return sensorInfoMapper.insertSensorInfo(sensorInfo);
    }

    /**
     * 修改【请填写功能名称】
     *
     * @param sensorInfo 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateSensorInfo(SensorInfo sensorInfo)
    {
        sensorInfo.setUpdateTime(DateUtils.getNowDate());
        return sensorInfoMapper.updateSensorInfo(sensorInfo);
    }

    /**
     * 批量删除【请填写功能名称】
     *
     * @param sensorIds 需要删除的【请填写功能名称】ID
     * @return 结果
     */
    @Override
    public int deleteSensorInfoByIds(Long[] sensorIds)
    {
        return sensorInfoMapper.deleteSensorInfoByIds(sensorIds);
    }

    /**
     * 删除【请填写功能名称】信息
     *
     * @param sensorId 【请填写功能名称】ID
     * @return 结果
     */
    @Override
    public int deleteSensorInfoById(Long sensorId)
    {
        return sensorInfoMapper.deleteSensorInfoById(sensorId);
    }

    /**
     * 启用或停用设备
     * @param sensorInfo
     * @return
     */
    @Override
    public int startOrStopSensor(SensorInfo sensorInfo) {
        return sensorInfoMapper.startOrStopSensor(sensorInfo);
    }

    /**
     * 根据设备id获取设备code
     * @param chipId
     * @return
     */
    @Override
    public String getChipCodeById(Long chipId) {
        return sensorInfoMapper.getChipCodeById(chipId);
    }

    /**
     * 根据设备id获取传感器的信息
     * @param chipId
     * @return
     */
    @Override
    public List<SensorInfo> selectSensorInfoByChipId(Long chipId) {
        return sensorInfoMapper.selectSensorInfoByChipId(chipId);
    }

    /**
     * 修改成置顶
     * @param sensorId
     */
    @Override
    public void updateSensorTop(Long sensorId) {
        SensorInfo sensorInfo = sensorInfoMapper.selectSensorInfoById(sensorId);
        Integer maxSort = sensorInfoMapper.selectMaxSort();
        sensorInfo.setSort(maxSort+1);
        sensorInfoMapper.updateSensorInfo(sensorInfo);
    }

    /**
     * 根据code找到Sensor
     * @param sensorCode 传感器code
     * @return
     */
    @Override
    public SensorInfo selectSensorByCode(String sensorCode) {
        return sensorInfoMapper.selectSensorByCode(sensorCode);
    }

    /**
     * 根据传感器名字找对象
     * @param sensorName
     * @return
     */
    @Override
    public SensorInfo getSensorByName(String sensorName) {
        return sensorInfoMapper.getSensorByName(sensorName);
    }

}
